//
//  AboutViewController.m
//  FunOCR
//
//  Created by Luke Du on 8/03/10.
//  Copyright 2010 __MyCompanyName__. All rights reserved.
//

#import "AboutViewController.h"


@implementation AboutViewController
@synthesize versionLabel;
@synthesize btnFollowus;
@synthesize btnEmailus;

- (void)dealloc {
    [super dealloc];
	
	[versionLabel release];
}






- (void)viewDidLoad {
    [super viewDidLoad];
	
	//self.view.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"background_image.png"]];
	
	
	NSBundle *mainBundle;
	
	mainBundle = [NSBundle mainBundle];
	
	NSLog(@"CFBundleVersion :: %@", [mainBundle objectForInfoDictionaryKey:@"CFBundleVersion"]);
	
	self.versionLabel.text = [mainBundle objectForInfoDictionaryKey:@"CFBundleVersion"];
}





//open twitter app to follow an user
- (void) openTwitterAppForFollowingUser:(NSString *)twitterUserName
{
	UIApplication *app = [UIApplication sharedApplication];
	
	// Tweetie: http://developer.atebits.com/tweetie-iphone/protocol-reference/
	NSURL *tweetieURL = [NSURL URLWithString:[NSString stringWithFormat:@"tweetie://user?screen_name=%@", twitterUserName]];
	if ([app canOpenURL:tweetieURL])
	{
		[app openURL:tweetieURL];
		return;
	}
	
	// Birdfeed: http://birdfeed.tumblr.com/post/172994970/url-scheme
	NSURL *birdfeedURL = [NSURL URLWithString:[NSString stringWithFormat:@"x-birdfeed://user?screen_name=%@", twitterUserName]];
	if ([app canOpenURL:birdfeedURL])
	{
		[app openURL:birdfeedURL];
		return;
	}
	
	// Twittelator: http://www.stone.com/Twittelator/Twittelator_API.html
	NSURL *twittelatorURL = [NSURL URLWithString:[NSString stringWithFormat:@"twit:///user?screen_name=%@", twitterUserName]];
	if ([app canOpenURL:twittelatorURL])
	{
		[app openURL:twittelatorURL];
		return;
	}
	
	// Icebird: http://icebirdapp.com/developerdocumentation/
	NSURL *icebirdURL = [NSURL URLWithString:[NSString stringWithFormat:@"icebird://user?screen_name=%@", twitterUserName]];
	if ([app canOpenURL:icebirdURL])
	{
		[app openURL:icebirdURL];
		return;
	}
	
	// Fluttr: no docs
	NSURL *fluttrURL = [NSURL URLWithString:[NSString stringWithFormat:@"fluttr://user/%@", twitterUserName]];
	if ([app canOpenURL:fluttrURL])
	{
		[app openURL:fluttrURL];
		return;
	}
	
	// SimplyTweet: http://motionobj.com/blog/url-schemes-in-simplytweet-23
	NSURL *simplytweetURL = [NSURL URLWithString:[NSString stringWithFormat:@"simplytweet:?link=http://twitter.com/%@", twitterUserName]];
	if ([app canOpenURL:simplytweetURL])
	{
		[app openURL:simplytweetURL];
		return;
	}
	
	// Tweetings: http://tweetings.net/iphone/scheme.html
	NSURL *tweetingsURL = [NSURL URLWithString:[NSString stringWithFormat:@"tweetings:///user?screen_name=%@", twitterUserName]];
	if ([app canOpenURL:tweetingsURL])
	{
		[app openURL:tweetingsURL];
		return;
	}
	
	// Echofon: http://echofon.com/twitter/iphone/guide.html
	NSURL *echofonURL = [NSURL URLWithString:[NSString stringWithFormat:@"echofon:///user_timeline?%@", twitterUserName]];
	if ([app canOpenURL:echofonURL])
	{
		[app openURL:echofonURL];
		return;
	}
	
	// --- Fallback: Mobile Twitter in Safari
	NSURL *safariURL = [NSURL URLWithString:[NSString stringWithFormat:@"http://mobile.twitter.com/%@", twitterUserName]];
	[app openURL:safariURL];
}





- (IBAction) followMe{
	NSLog(@"follow clicked");
	[self openTwitterAppForFollowingUser:@"bluepinme2010"];
}





- (IBAction) emailUs{
	
	
	NSBundle *mainBundle;
	
	mainBundle = [NSBundle mainBundle];
	
	//NSString *subject = [@"Feedback on FunOcr" stringByAddingPercentEscapesUsingEncoding: NSUTF8StringEncoding];
	
	//NSString *subject = @"Feedback@on@FunOcr";
	
	//NSString *body = [@"This email is about FunOcr version " stringByAddingPercentEscapesUsingEncoding: NSUTF8StringEncoding];
    //NSString *body = [NSString stringWithFormat:@"This email is about FunOcr version %@",[mainBundle objectForInfoDictionaryKey:@"CFBundleVersion"]];
	
	NSString *urlString = [NSString stringWithFormat:@"mailto:bluepinme@gmail.com"];
	
	//NSString *urlString = [NSString stringWithFormat:@"mailto:bluepinme2009@gmail.com?su"];
	
	NSLog(@"urlString :: %@", urlString);
	
	NSURL *url = [NSURL URLWithString:urlString];
	[[UIApplication sharedApplication] openURL:url];
}
@end
